/*编写一个贯穿全局类*/
function MagicalCoder(){
    this.components = [];//新版组件管理方式
    this.dragItems = [];//左侧拖拽源
}
/*安装组件*/
MagicalCoder.prototype.install = function(param){
    var components = param.components;
    for(var i=0;i<components.length;i++){
        this.components.push(components[i]);
    }
    var dragItems = param.dragItems;
    for(var i=0;i<dragItems.length;i++){
        this.dragItems.push(dragItems[i]);
    }
}
/*获取安装的组件*/
MagicalCoder.prototype.getComponents = function(){
    return this.components;
}
/*
引入远程资源
imports:[]
例如:["xxx.js","xxx.css"]
*/
MagicalCoder.prototype.import = function(imports){
    var resources = []
    for(var i=0;i<imports.length;i++){
        if(!imports[i]){
            continue;
        }
        if(imports[i].endsWith(".js")){
            resources.push('<script src="'+imports[i]+'" type="text/javascript"></sc' + 'ript>');
        }else if(imports[i].endsWith(".css")){
            resources.push('<link href='+imports[i]+' rel="stylesheet" type="text/css" />');
        }
    }
    document.write(resources.join(''))
}
/*安装插件到constant中*/
MagicalCoder.prototype.installConstantComponents = function(param){
/*左侧拖拽组件合并*/
    var dragItems = param.dragItems;
    for(var i=0;i<this.dragItems.length;i++){
        dragItems.push(this.dragItems[i]);
    }
/*命名空间，右侧属性合并*/
    var rightPanel = param.rightPanel;//右侧属性
    var tagClassMapping = param.tagClassMapping;//命名空间
    var installedComponents = this.getComponents();
    var rightPaneSize = rightPanel.length;
    for(var i=0;i<installedComponents.length;i++){
        var identifier = installedComponents[i].identifier;
        var properties = installedComponents[i].properties;
        var attributes = installedComponents[i].attributes;
        //组件空间
        tagClassMapping[identifier] = properties;
        //右侧属性 注意自定义组件 不要越界
        for(var j=0;j<attributes.length;j++){
            if(j<rightPaneSize){
                //这里是合并还是覆盖
                var originConfig = rightPanel[j].content[identifier];
                if(typeof originConfig == 'undefined'){
                    rightPanel[j].content[identifier] = attributes[j];
                }else {
                    for(var n=0;n<attributes[j].length;n++){
                        originConfig.push(attributes[j][n]);//
                    }
                }
            }else{
                console.log(identifier+"组件超越了constant.js配置的this.rightPanel最大长度【已忽略】")
            }
        }
    }
}
var MagicalCoder = new MagicalCoder();
